#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

struct vip{
	int id;
	int shi;
};

bool cmp( vip a,vip b){
    return a.shi<b.shi;	
}

vector<vip>::iterator findid(vip s,vector<vip> &v){
	for( vector<vip>::iterator i=v.begin(); i!=v.end(); i++ ){
		if( s.id==i->id ){
			return i;
		}
	}
}

int main(){
	int n;
	vip s;
	vector <vip> v;
	cin>>n;
	s.id=1;s.shi=1000000000;
	v.push_back(s);
	for( int i=0; i<n; i++ ){
		cin>>s.id>>s.shi;
		v.push_back(s);
		sort(v.begin(),v.end(),cmp);
	    vector<vip>::iterator p=findid(s,v);
		if( p==v.begin() ){
			cout<<p->id<<" "<<(p+1)->id; 
		} else if( p==v.end()-1 ){
			cout<<p->id<<" "<<(p-1)->id;
		} else if( ((p+1)->shi-p->shi)<(p->shi-(p-1)->shi) ){
			cout<<p->id<<" "<<(p+1)->id;
		} else {
			cout<<p->id<<" "<<(p-1)->id;
		}
		if( i!=n-1 )
		cout<<endl;
	}
	return 0;
}
